<template>
    <div>

    <el-row >
           <el-col :span="24">
            <el-form   class="demo-form-inline">
              <el-form-item >
                  <el-input  placeholder="请输入企业名称" v-model="enterpriseName" style="float:left;width:300px;margin-left:200px"></el-input>
                  <el-button icon="el-icon-search"  type="primary"  style="float:left" @click="doSearchBtn"></el-button>
               </el-form-item>
                 </el-form>
                 
           </el-col>
    </el-row>

    <el-row>
      <el-col :span="24">
        <el-table
    :data="tableData"
    border
    style="width: auto;">
    <el-table-column
      type="index"
      label="序号"
      align="center"
      width="50"
    ></el-table-column>
    <el-table-column
      label="融资企业名称"
      align="center"
      >
      <template slot-scope="scope">
        {{ scope.row.enterpriseName }}
      </template>
    </el-table-column>
    <el-table-column
    prop="legal"
      label="法人"
      align="center">
    </el-table-column>
    <el-table-column
      prop="legalPhone"
      label="手机号"
      align="center">
    </el-table-column>
    <el-table-column
      prop="legalId"
      label="法人身份证号"
      align="center">
    </el-table-column>
    <el-table-column
      label="营业执照号"
      align="center">
      <template slot-scope="scope">
       {{ scope.row.businessLicense }}
      </template>
    </el-table-column>
   
    <el-table-column
      label="推荐企业"
      align="center">
      <template slot-scope="scope">
        <el-button type="primary" @click="doSend(scope.row)">推荐</el-button>
    </template>
    </el-table-column>
   
    
  </el-table>
      </el-col>
    </el-row>

    <el-row>
           <el-col :span="24" :offset="6">
            <el-pagination
              
              background
              @size-change="sizeChange"
              @current-change="currentChange"
              :current-page="pageNum"
              :page-sizes="[3, 6, 9]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
            </el-pagination>
            </el-col>
        </el-row>

        <el-dialog  title="推荐企业" :visible.sync="showing" >
            <el-row>
            <el-col :span="20" >
                <el-form :model="finance" style="font-size:35px;" >
                    <el-form-item label="企业编码:" label-width="100px">
                        <template>{{ finance.enterpriseId }}</template>
                    </el-form-item>
                    <el-form-item label="企业名称:" label-width="100px">
                        <template>{{ finance.enterpriseName }}</template>
                    </el-form-item>
                    <el-form-item label="法人:" label-width="100px">
                        <template>{{ finance.legal }}</template>
                    </el-form-item>
                    <el-form-item label="手机号:" label-width="100px">
                        <template>{{ finance.legalPhone }}</template>
                    </el-form-item>
                    <el-form-item label="法人身份证号:" label-width="100px" >
                        <template>{{ finance.legalId }}</template>
                    </el-form-item>
                    <el-form-item label="营业执照号:" label-width="100px">
                        <template>{{ finance.businessLicense }}</template>
                    </el-form-item>
                </el-form> 
                    <template style=" margin-left: 30px">接收企业:</template>
                    <el-autocomplete
                    
                    class="inline-input"
                    v-model="state"
                    :fetch-suggestions="querySearch"
                    placeholder="请输入核心企业名称"
                    @select="handleSelect"
                    clearable
                ></el-autocomplete>

                
            </el-col>
            </el-row>
        
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="showing = false">取消</el-button>
            <el-button type="primary" @click="doAddRecord">确 定</el-button>
            </div>
        </el-dialog>
  </div>
</template>

<script>
export default {
        data(){
            return{
                timeout:  null,
                coreList:[],
                state:'',
                showing:false,
                tableData:[],
                pageNum:1,
                pageSize:3,
                total:0,
                enterpriseName:'',
                recordForm:{
                    financeId:'',
                    coreId:'',
                },
                finance:{}
            }
        },
        created(){
            this.getList()
            this.getCoreList()
        },
        methods:{
            doAddRecord(){
                if(this.state==''){
                    this.$message({
                            message:'接收企业不能为空',
                            type:'warning'
                        })
                    return;
                }
                this.$axios.post('api/recommendationRecord/insertRecord',this.recordForm,{headers:{'jwt':localStorage.getItem('jwt')}})
                .then(res=>{
                    if(res.data.code==200){
                        this.$message({
                            message:'推荐成功',
                            type:'success'
                        })
                        this.showing = false
                        this.getList()
                    }else{
                        this.$message({
                            message:'网络异常',
                            type:'error'
                        })
                    }
                })
            },
            handleSelect(item){
                this.recordForm.coreId = item.id
            },
            querySearch(queryString,cb){
                let dataList = []

                this.coreList.forEach(res =>{
                    let param = {'id':res.coreId,'value':res.enterpriseName}
                    dataList.push(param)
                })
                    var results = queryString ? dataList.filter(this.createFilter(queryString)) : dataList;
                    // 调用 callback 返回建议列表的数据
                    cb(results);

            },
                createFilter(queryString) {
                return (res) => {
                return (res.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
                };
            },
            getCoreList(){
                let param = '1s1s'
                this.$axios.get('api/CoreEnterprise/queryCoreByName?enterpriseName='+param,{headers:{'jwt':localStorage.getItem('jwt')}})
                .then(res=>{
                    this.coreList = res.data.data
                    console.log(this.coreList)
                    
                })
            },
            doSend(row){
                this.state = ''
                this.finance = {}
                this.recordForm.financeId = ''
                this.recordForm.coreId = ''
                this.showing = true
                this.finance = row
                this.recordForm.financeId = row.enterpriseId
            },
            doSearchBtn(){
                this.pageNum = 1
                this.getList()
            },
            currentChange(p){
                this.pageNum=p
                this.getList()
             },
            sizeChange(p){
                this.pageNum=1
                this.pageSize=p
                this.getList()
            },
            getList(){
                let param ={}
                param.pageNum = this.pageNum
                param.pageSize = this.pageSize
                let data = {}
                data.enterpriseName = this.enterpriseName
                param.data = data
                this.$axios.post('api/finance/queryFinanceIntoPlatformAuditRecord',param,{headers:{'jwt':localStorage.getItem('jwt')}})
                .then(res =>{

                    let pageDate = res.data.data
                    console.log(pageDate)
                    this.tableData = pageDate.list
                    this.pageNum = pageDate.pageNum
                    this.pageSize = pageDate.pageSize
                    this.total = pageDate.total
                })
            }
        }
}
</script>

<style scoped>
    .inline-input{
        margin-left: 45px;
    }
</style>